<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Member extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Member_model', 'Member');
        $this->load->library('encrypt');
    }

    //登录
    public function login() {
		// admin 2FCoNYgw1IaUsAHTgQ75sSdIfgiVJloNHVXfQtcmQncHHtrbf/tWSJKoPwjYf89VCly5GaDtXlVevZPK4r/bFA==
		// Quit@smoking4ever ly10KihgeyChD6XK19AKs6f9xehy1sQUcX4nyLfFWKDjruFzKJNmxRf85eKpAnfrMoAn85NgrrYu3rUw3wdlHg==
        $hour = date('H');
        if ($hour <= 11) {
            $welcome_msg = '早上好，';
        } else if (11 < $hour && $hour <= 13) {
            $welcome_msg = '中午好，';
        } else if (13 < $hour && $hour <= 17) {
            $welcome_msg = '下午好，';
        } else if ($hour > 17) {
            $welcome_msg = '晚上好，';
        }
        $data['welcome_msg'] = $welcome_msg;
        $data['bgimg_num'] = mt_rand(0, 5);
        $this->db->select('site_icon');
        $query = $this->db->get('ci_site_config')->result_array();
        $data['site_icon'] = $query[0]['site_icon'];
        $this->load->view('/admin/login', $data);
    }

    //登录检查
    public function check_login() {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $ret = $this->Member->checkLogin($username, $password);
//		$ret === TRUE && redirect('/admin/dashboard/');
        if ($ret === TRUE) {
            echo 1;
        } else {
            echo 0;
        }
    }

    //注销
    public function logout() {
        $this->session->sess_destroy();
        redirect('/welcome/index/');
    }

    //注册
    public function register() {
        $this->load->view('/admin/register');
    }

    //注册检查
    public function check_register() {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $ret = $this->Member->creatAdmin($username, $password);
        if (!$ret) {
            show_error('注册失败!');
        } else {
            redirect('/member/login/');
        }
    }

}
